<?php
$this->breadcrumbs=array(
	'Ambientes'=>array('index'),
	'Administrar',
);
Yii::app()->clientScript->registerScript('search', "
    $('.search-button').click(function(){
        $('.search-form').toggle();
        return false;
    });
    $('.search-form form').submit(function(){
        $.fn.yiiGridView.update('ambiente-grid', {
                data: $(this).serialize()
        });
        return false;
    });
    afterajax(id,data){
        tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
    }
");

?>

<h1>Consultar Ambientes</h1>
<?php echo CHtml::link('Pesquisa Avançada','#',array('class'=>'search-button', "onclick"=>"$('.search-form').toggle();")); ?>
<div class="search-form" style="display:none">
    <div class="wide form">
        <?php $form=$this->beginWidget('CActiveForm', array(
                'id'=>'ambiente-search-form',
                'enableAjaxValidation'=>false,
                'enableClientValidation'=>false,
                'action'=>Yii::app()->createUrl($this->route),
                'method'=>'get'
        )); ?>
            <div class="row">
                <?php echo $form->label($model,'ID_PREDIO'); ?>
                <?php
                    $dados = array(-1=>'Selecione');
                    $dados += $model->getPredios();
                    echo $form->dropDownList($model,'ID_PREDIO', $dados); 
                ?>
            </div>
            <div class="row">
                <?php echo $form->label($model,'NU_CAPACIDADE'); ?>
                <?php echo $form->textField($model,'NU_CAPACIDADE'); ?>
                <span>Ex.: >=30</span>
            </div>
            <table class="tbChkList">
                <tr>
                    <td>
                        <div class="row">
                            <label >Recursos</label>
                            <div class="chkList">

                                <?php
                                    $dados = $modelAR->getRecursos();
                                    /*
                                    $i = 0;
                                    foreach ($dados as $key => $value) {
                                        echo '<input type="checkbox"'.
                                                ' id="Ambiente_Recurso_ID_RECURSO_'. $i . '" '.
                                                ' name="Ambiente_Recurso[]'. '" '.
                                                ' value="' . $key . '"'.
                                                ' />';
                                        echo '<label for="Ambiente_Recurso_ID_RECURSO_'.$i.'">'. $value . '</label>';
                                        echo '<br>';
                                        $i++;
                                    }
                                     */
                                    echo $form->checkBoxList($modelAR, 'ID_RECURSO', $dados);
                                ?>

                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="row">
                            <label >Usos</label>
                            <div class="chkList">

                                <?php
                                    $dados = $modelAU->getUsos();
                                    /*
                                    $existentes = $modelAU->getUsosByAmbiente();
                                    $i = 0;
                                    foreach ($dados as $key => $value) {
                                        $chk = empty($existentes[$key]) ? ' ' : ' checked="checked" ';
                                        echo '<input type="checkbox"'.
                                                ' id="Ambiente_Uso_ID_USO_'. $i . '" '.
                                                ' name="Ambiente_Uso[]'. '" '.
                                                ' value="' . $key . '"'. $chk .
                                                ' />';
                                        echo '<label for="Ambiente_Recurso_ID_USO_'.$i.'">'. $value . '</label>';
                                        echo '<br>';
                                        $i++;
                                    }
                                     */
                                    echo $form->checkBoxList($modelAU, 'ID_USO', $dados);
                                    //echo $form->textField($modelAR, 'NU_QUANTIDADE', array('name'=>'Ambiente_Recurso[NU_QUANTIDADE][]'));
                                ?>

                            </div>
                        </div>
                    </td>
                </tr>
            </table>
            <div class="row buttons">
                    <?php echo CHtml::submitButton('Pesquisar'); ?>
            </div>
        <?php $this->endWidget(); ?>
    </div>
</div><!-- search-form -->
<?php 
    $dt = new DateTime("now");
    $now = date("d/m/Y", $dt->getTimestamp());
    $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'ambiente-grid',
	'dataProvider'=>$model->with('recursos', 'usos', 'iD_PREDIO')->advancedSearch(),
        'afterAjaxUpdate'=>'afterajax',
	'columns'=>array(
            'iD_PREDIO.TX_DESCRICAO',
            'TX_NOME',
            'NU_CAPACIDADE',
            array
            (
                'class'=>'CButtonColumn',
                'template'=>'{detalhe}{reservas}',
                'buttons'=>array
                (
                    'detalhe' => array
                    (
                        'label'=>'Detalhes',
                        'imageUrl'=>Yii::app()->request->baseUrl.'/assets/884ba3ad/gridview/view.png',
                        'url'=>'Yii::app()->createUrl("ambiente/viewPopup", array("id"=>$data->ID_AMBIENTE, "height"=>300, "width"=>400))',
                        'options'=>array('class'=>'thickbox')
                    ),
                    'reservas' => array
                    (
                        'label'=>'Reservas',
                        'imageUrl'=>Yii::app()->request->baseUrl.'/assets/884ba3ad/gridview/calendar.png',
                        'url'=>'Yii::app()->createUrl("consulta/sala", array("a"=>$data->ID_PREDIO, "b"=>$data->ID_AMBIENTE))',//http://localhost/alocainf/index.php?r=consulta/sala&a=1&b=33&c=02%2F10%2F2011
                    ),
                ),
            ),
	),
)); ?>